package com.violet.controller.manager;

import com.violet.domain.dto.manager.MProductDto;
import com.violet.domain.result.Result;
import com.violet.domain.result.ResultPage;
import com.violet.domain.search.MyPage;
import com.violet.domain.search.manager.MProductSearch;
import com.violet.domain.vo.manager.MProductVo;
import com.violet.service.manager.MProductService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/manager/product")
@RequiredArgsConstructor
public class MProductController {

    private final MProductService service;

    // 分页搜索
    @GetMapping("/search")
    public ResultPage<List<MProductVo>> search(@ModelAttribute MProductSearch search, @ModelAttribute MyPage myPage) {
        return service.search(search, myPage);
    }

    @PostMapping
    public Result<MProductVo> create(@ModelAttribute MProductDto dto) {
        return Result.success(service.create(dto), "创建数据");
    }

    @DeleteMapping("/{id}")
    public Result<Boolean> deleteById(@PathVariable String id) {
        return Result.success(service.deleteById(id), "删除数据");
    }

    @PutMapping("/{id}")
    public Result<MProductVo> updateById(@PathVariable String id, @ModelAttribute MProductDto dto) {
        return Result.success(service.updateById(id, dto), "更新数据");
    }

    // 添加标签
    @PutMapping("/tags")
    public Result<MProductVo> addTag(@RequestParam String tags, @RequestParam String id) {
        return Result.success(service.addTag(id, tags), "添加标签");
    }

    @DeleteMapping("/tags")
    public Result<MProductVo> deleteTags(@RequestParam String tags, @RequestParam String id) {
        return Result.success(service.deleteTag(id, tags), "删除标签");
    }

}
